{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Creating Image Trigger Poison Samples with ART\n",
    "\n",
    "This notebook shows how to create image triggers in ART with RBG and grayscale images."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import os, sys\n",
    "%matplotlib inline\n",
    "\n",
    "module_path = os.path.abspath(os.path.join('..'))\n",
    "if module_path not in sys.path:\n",
    "    sys.path.append(module_path)\n",
    "\n",
    "from art.estimators.classification import KerasClassifier\n",
    "from art.attacks.poisoning import PoisoningAttackBackdoor\n",
    "from art.attacks.poisoning.perturbations import add_pattern_bd, add_single_bd, insert_image\n",
    "from art.utils import load_mnist, preprocess, load_cifar10\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "(x_raw, y_raw), (x_raw_test, y_raw_test), min_, max_ = load_mnist()\n",
    "\n",
    "# Random Selection:\n",
    "n_train = np.shape(x_raw)[0]\n",
    "num_selection = 7500\n",
    "random_selection_indices = np.random.choice(n_train, num_selection)\n",
    "x_raw = x_raw[random_selection_indices]\n",
    "y_raw = y_raw[random_selection_indices]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "idx = 0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Note the shape of `x_raw`, black and white images must still have a color channel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x_raw shape: (7500, 28, 28, 1)\n"
     ]
    }
   ],
   "source": [
    "print(f\"x_raw shape: {x_raw.shape}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7ff4715ed6a0>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAM20lEQVR4nO3db4xc9XXG8efBrNeJsYNdY+MaN6TUUYqq1qQrU9VVRYQSEVeV4UUqrDQyFa1TNaikjapS+gJLfeNGTVAkoihLsWIiCopEEG6KEoyVCKVKHdbI9Z+6qSl1ieON16lT2dBgr3dPX+wl2pid3ywzd+YOPt+PtJqZe+bOPbrw+N6Z39z5OSIE4PJ3RdMNAOgPwg4kQdiBJAg7kARhB5K4sp8bW+jhWKTF/dwkkMrrek0X4rznqnUVdtu3SfqcpAWS/j4idpSev0iLdbNv7WaTAAr2xd6WtY5P420vkPR5SR+WdKOkLbZv7PT1APRWN+/ZN0h6KSJejogLkp6QtLmetgDUrZuwr5H0/VmPT1TLfobtbbbHbI9N6nwXmwPQjW7CPteHAG/67m1EjEbESESMDGm4i80B6EY3YT8hae2sx9dJOtldOwB6pZuwvyBpne332F4o6U5Ju+tpC0DdOh56i4iLtu+R9A3NDL3tjIgjtXUGoFZdjbNHxDOSnqmpFwA9xNdlgSQIO5AEYQeSIOxAEoQdSIKwA0kQdiAJwg4kQdiBJAg7kARhB5Ig7EAShB1IgrADSRB2IAnCDiRB2IEkCDuQBGEHkiDsQBKEHUiCsANJEHYgCcIOJEHYgSQIO5AEYQeSIOxAEoQdSIKwA0l0NWWz7eOSzkmaknQxIkbqaApA/boKe+UDEfGjGl4HQA9xGg8k0W3YQ9Kztvfb3jbXE2xvsz1me2xS57vcHIBOdXsavzEiTtpeKWmP7X+PiOdnPyEiRiWNStJSL48utwegQ10d2SPiZHU7Iek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S/qwpE9Up6uYn3lN490vc0wzPhA6nf68W02E/YSktbMeXyfpZAN9zCkiTla3E5Ke0uBNRX3qjRl0q9uJhvv5qUGaxnuuacY1APuuyenPmwj7C5LW2X6P7YWS7pS0u4E+3sT24uqDE9leLOlDGrypqHdL2lrd3yrp6QZ7+RmDMo13q2nG1fC+a3z684jo+5+kTZr5RP4/Jf11Ez206OsXJf1r9Xek6d4kPa6Z07pJzZwR3S3p5yTtlXSsul0+QL19WdIhSQc1E6zVDfX2W5p5a3hQ0oHqb1PT+67QV1/2G1+XBZLgG3RAEoQdSIKwA0kQdiAJwg4kQdiBJAg7kMT/A0HY0pKcpkanAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(x_raw[idx].squeeze())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7ff471611c50>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAMwElEQVR4nO3df4wcdRnH8c/HclzhaLWVUi5tBUQ0EBOrXoqxxmCIBolJ8Q8NjZqqxKqBqPFHJPgHJP6DP8CYYIwnNBaDqAkiNSFqvRCJiVaupEKxahErlp49TDEtKu31+vjHDXqW3dljZ3Zn8Xm/ksvuzrO782TTT2d2vjP7dUQIwP+/FzXdAID+IOxAEoQdSIKwA0kQdiCJU/q5slM9HIs10s9VAqk8o3/oWBx1q1q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lf+tbA8zOovQ1qXxK9davO3s6JiBWtCn0N+3NWbk9GxFhjDZQY1N4GtS+J3rrVr97YjQeSIOxAEk2Hfbzh9ZcZ1N4GtS+J3rrVl94a/c4OoH+a3rID6BPCDiTRSNhtX2b797YftX1tEz20Y3uf7Ydt77I92XAvW2xP2949b9ly29tt7y1uW86x11BvN9h+ovjsdtm+vKHe1ti+z/Ye24/Y/nixvNHPrqSvvnxuff/ObnuRpD9Iequk/ZIekLQxIn7b10basL1P0lhENH4Chu03S3pa0u0R8epi2RclHYqIG4v/KJdFxGcHpLcbJD3d9DTexWxFo/OnGZd0haT3q8HPrqSvd6sPn1sTW/Z1kh6NiMci4pik70ra0EAfAy8i7pd06KTFGyRtLe5v1dw/lr5r09tAiIipiHiwuH9E0rPTjDf62ZX01RdNhH2VpL/Me7xfgzXfe0j6qe2dtjc33UwLKyNiSpr7xyPprIb7OVnHabz76aRpxgfms+tm+vOqmgh7q9/HGqTxv/UR8TpJb5d0dbG7ioVZ0DTe/dJimvGB0O3051U1Efb9ktbMe7xa0oEG+mgpIg4Ut9OS7tbgTUV98NkZdIvb6Yb7+Y9Bmsa71TTjGoDPrsnpz5sI+wOSLrB9nu1TJV0paVsDfTyH7ZHiwIlsj0h6mwZvKuptkjYV9zdJuqfBXv7HoEzj3W6acTX82TU+/XlE9P1P0uWaOyL/R0mfa6KHNn29XNJvir9Hmu5N0p2a262b0dwe0VWSXippQtLe4nb5APX2bUkPS3pIc8Eabai3N2nuq+FDknYVf5c3/dmV9NWXz43TZYEkOIMOSIKwA0kQdiAJwg4kQdiBJAg7kARhB5L4N12M1PbY8RexAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "backdoor_attack = PoisoningAttackBackdoor(lambda x: insert_image(x, \n",
    "                                                                 backdoor_path='../utils/data/backdoors/alert.png',\n",
    "                                                                 size=(10,10),\n",
    "                                                                 mode='L',\n",
    "                                                                ))\n",
    "poisoned_x, poisoned_y = backdoor_attack.poison(x_raw[:20], y_raw[:20])\n",
    "plt.imshow(poisoned_x[idx].squeeze())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "(x_raw, y_raw), (x_raw_test, y_raw_test), min_, max_ = load_cifar10()\n",
    "\n",
    "# Random Selection:\n",
    "n_train = np.shape(x_raw)[0]\n",
    "num_selection = 1\n",
    "random_selection_indices = np.random.choice(n_train, num_selection)\n",
    "x_raw = x_raw[random_selection_indices]\n",
    "y_raw = y_raw[random_selection_indices]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x_raw shape: (1, 32, 32, 3)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7ff4717af1d0>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD5CAYAAADhukOtAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAddklEQVR4nO2daaxd13Xf/+vOb36P82iSkmVLqixLKiModWC4jhvIThDZQBPYQAN9MMygiIEaSA0ILlC7QD84RW3DHwoXdC1EKVwP8VCrgZtEEGLIaVLJlC1rogZKpkiKFB+HR/JNd179cK8KStn/9Z7ecB+j/f8BBO/b6+5z9tnnrHPu3f+71jJ3hxDi7U9howcghBgMcnYhMkHOLkQmyNmFyAQ5uxCZIGcXIhNKq+lsZncD+CqAIoD/5u5fjN5fLphXCpa0RXcd0gWk+fXBUVO9G+0r2KqnOw6V+TSWa0PU1u10qG1kYo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FyIT5OxCZIKcXYhMkLMLkQlydiEyQc4uRCb8P9eMsax+Xw+2AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "print(f\"x_raw shape: {x_raw.shape}\")\n",
    "plt.imshow(x_raw[idx])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The ART method `insert_image` has different parameters that can affect image trigger generation.\n",
    "\n",
    "If `random=True`, the image will in a different random location for each sample. If `random=False`, the placement of each trigger depends on the values of `x_shift` and `y_shift`. \n",
    "\n",
    "You may also set `channels_first=True` if working with images of shape `(N, C, W, H)` instead of `(N, W, H, C)`\n",
    "\n",
    "The mode affects how Pillow processes the image. This is usually `RGB` for color images or `L` for 8-bit black and white images. More information [here](https://pillow.readthedocs.io/en/stable/handbook/concepts.html#concept-modes).\n",
    "\n",
    "The `blend` parameter affects how much the two images should blend into each other. The default blend is 0.8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def poison_func(x):\n",
    "    return insert_image(x, backdoor_path='../utils/data/backdoors/alert.png',\n",
    "                        size=(10,10), mode='RGB', blend=0.8, random=True)\n",
    "backdoor_attack = PoisoningAttackBackdoor(poison_func)\n",
    "poisoned_x, poisoned_y = backdoor_attack.poison(x_raw[:20], y_raw[:20])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7ff490883400>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD5CAYAAADhukOtAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2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bz8mmJXkd1ArjS1Yb34neSufTAH5/i8ZwM3pKwOMAnhzkOAB8Ab2vgy30vum8H8BOAA8C+GH//x1bNI6/AvAEgGPoOdu+AYzjreh9JT0G4LH+v3cOek6CcQx0TgD8DHpJXI+hd2H5g6vO2f8CcBLA3wCoXst29QSdEJmgJ+iEyAQ5uxCZIGcXIhPk7EJkgpxdiEyQswuRCXJ2ITJBzi5EJvwPaD2EgfNKccIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(poisoned_x[0].squeeze())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
